import serial
import time

start_time = time.time()
# 打开串口
ser = serial.Serial('COM10', 9600, timeout=0)  # 请根据实际情况修改串口名和波特率

# 写数据到串口
ser.write(b'Hello')

clock = 0
while clock < 1000:
    # 从串口读数据
    data = ser.read(1024)  # 读取10个字节的数据
    if data!=b'':
        print(str(data, encoding='utf-8'))
    time.sleep(0.02)
    # print("clock:",clock)
    clock += 1
# 关闭串口
ser.close()

print("--- %s seconds ---" % (time.time() - start_time))